package com.sinoyd.itszyw.Util;

import android.content.Context;
import android.util.Log;
import android.widget.Toast;

/**
 * @createBy    : Sinoyd 大饼洲
 * @description : 全图crash
 * @projectName : ITYW
 * @creationDate: 2017-03-13 14:36
 */
public class CrashHandlerUtils implements Thread.UncaughtExceptionHandler  {

//    public final Logger mLogger = Logger.getLogger(getClass());

    private static CrashHandlerUtils INSTANCE = new CrashHandlerUtils();
    private Thread.UncaughtExceptionHandler mDefaultUEH;
    private Context mContext;

    private CrashHandlerUtils() {
        mDefaultUEH = Thread.getDefaultUncaughtExceptionHandler();
    }

    public static CrashHandlerUtils getInstance() {
        return INSTANCE;
    }

    public void init(Context ctx) {
        Thread.setDefaultUncaughtExceptionHandler(this);
        mContext = ctx;
    }

    @Override
    public void uncaughtException(Thread thread, Throwable ex) {
        Log.e("CrashHandlerUtils", ex.getMessage(), ex);
        mDefaultUEH.uncaughtException(thread, ex);
        Toast.makeText(mContext,ex.getMessage(),Toast.LENGTH_LONG).show();
    }

}

